#include<bits/stdc++.h>
using namespace std;
map<string,int> st;
bool isid(string str){
	int a[7]={},j=0;
	int flag=0;
	for(int i=0;i<str.length();++i){
		if(!(a[j]==0&&str[i]=='0')&&str[i]!='.'&&str[i]!=':'){
			a[j]=a[j]*10+(str[i]-48);
		}
		else if(str[i]!='.'&&str[i]!=':'){
			++flag;
		}
		if((j==0&&str[i]!='.'&&!(str[i]>='0'&&str[i]<='9'))||
		(j==1&&str[i]!='.'&&!(str[i]>='0'&&str[i]<='9'))||
		(j==2&&str[i]!='.'&&!(str[i]>='0'&&str[i]<='9'))||
		(j==3&&str[i]!=':'&&!(str[i]>='0'&&str[i]<='9'))){
			return 0;
		}
		if((j==0&&str[i]=='.')||
		(j==1&&str[i]=='.')||
		(j==2&&str[i]=='.')||
		(j==3&&str[i]==':')){
			if((flag==1&&a[j]!=0)||flag>1) return 0;
			if((a[j]<=255&&j!=5)||(a[j]<=65535&&j==5)){
				++j;
				flag=0;		
			} 
			else return 0;
		}
	}
	if(((flag==1&&a[j]!=0)||flag>1)||a[j]>65535) return 0;
	return 1;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout); 
	int n,m=1;
	cin>>n;
	while(n--){
		string op,ad;
		cin>>op>>ad;
		if(op=="Server"){
			if(!isid(ad)){
				cout<<"ERR"<<endl;
				continue; 
			}
			bool flag=0;
			int a=st.size();
			for(map<string,int>::iterator it=st.begin();it!=st.end();++it){
				if(it->first==ad){
					cout<<"FAIL"<<endl;flag=1;
					break;
				}
			}
			pair<string,int> b=make_pair(ad,m++);
			st.insert(b);
			if(!flag)cout<<"OK"<<endl;
		}
		if(op=="Client"){
			m++;
			if(!isid(ad)){
				cout<<"ERR"<<endl;
				continue; 
			}
			bool flag=0;
			int i=1;
			for(map<string,int>::iterator it=st.begin();it!=st.end();++it){
				if(it->first==ad){
					cout<<it->second<<endl;flag=1;
					break;	
				}
			}
			if(!flag) cout<<"FAIL"<<endl;
		}
	}
	return 0;
}
